/*
 * Created by SharpDevelop.
 * User: Robert
 * Date: 7/13/2006
 * Time: 11:12 AM
 */

using System;

namespace cs2335.cvslab.person
{
	/// <summary>
	/// This class represents a person.
	/// </summary>
	public class Person2 : Person
	{
		public Person2(string pname) : base(pname)
		{
		}
		///<summary>
		///  This method should take the input
		///  and return the characters in random order
		///  for example, given the input gtg123b, it
		///  should return "1g2b3tg".
		/// </summary>
		/// <param name="input">
		///   The string to perform the operation on
		/// </param>
        /// <returns>The scrambled string</returns>
		public override string Process(string input)
		{
			//Peron 2  put implementation here
            string resultString = "";
            char[] charString = input.ToCharArray();
            char[] resultCharString = new char[charString.Length];

            for (int i = 0; i < resultCharString.Length; i++)
            {
                resultCharString[i] = '\n';
            }

            for (int i = 0; i < charString.Length; i++)
            {
                Random random = new Random();
                int nextCharacter = random.Next(resultCharString.Length);
                while (resultCharString[nextCharacter] != '\n')
                {
                    nextCharacter = random.Next(resultCharString.Length);
                }
                resultCharString[nextCharacter] = charString[i];
            }

            for (int i = 0; i < resultCharString.Length; i++)
            {
                resultString = resultString + resultCharString[i];
            }

            return resultString;
		}

	}
}
